<template>
  <page-list :x-uri="uri" :custom-components="custom" :checkbox-item="false" :doactions="doactions">
    <!-- 自定义tab -->
    <template v-slot:page-tabs>
      <tabs :course-id="courseId" />
      <page-header :content="headerTitle" />
    </template>
  </page-list>
</template>
<script>
import PageList from '@public/template/page_list.vue';
import Tabs from './tabs';
import PageHeader from '@/components/page-header';
import User from '@/pages/user/student/account/components/user.vue';
export default {
  components: {
    PageList,
    Tabs,
    PageHeader
  },
  inject: ['reload'],
  data() {
    return {
      headerTitle: '课程评论',
      uri: '/course/admin/comment/' + this.$route.params.id + '/list',
      custom: {
        user: User
      },
      doactions: [
        { title: '删除', callback: this.delete }
      ]
    };
  },
  computed: {
    courseId() {
      return this.$route.params.id
    }
  },
  methods: {
    delete({ row }) {
      this.$box
          .confirm('确认删除吗')
          .then(() => {
            this.$http.delete(
                '/course/admin/comment/' + row.course_id + '/' + row.id + '/delete',
                {},
                response => {
                  this.$message.success(response.msg, _ => {
                    this.reload();
                  });
                },
                error => {
                  this.$message.error(error.msg);
                }
            );
          })
          .catch(() => {});
    }
  }
};
</script>
